﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;

namespace RooHui.Infrastructure.Entities.Repository
{
    [Table("U_Account")]
    public class U_Account : IEntity<U_Account>
    {
        [Key]
        [Column(TypeName = "varchar")]
        [StringLength(128)]
        public string UserName { get; set; }
        public int Platfrom { get; set; }
        [Column(TypeName = "varchar")]
        [StringLength(128)]
        public string AccountNo { get; set; }
        public decimal BalanceAmount { get; set; }
        public decimal FrozenAmount { get; set; }

        public override U_Account Find(string key)
        {
            return Find(c => c.UserName == key);
        }

        public override U_Account Find(System.Linq.Expressions.Expression<Func<U_Account, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.Account.FirstOrDefault(where);
                if (item != null)
                {
                    this.AccountNo = item.AccountNo;
                    this.BalanceAmount = item.BalanceAmount;
                    this.FrozenAmount = item.FrozenAmount;
                    this.Platfrom = item.Platfrom;
                    this.UserName = item.UserName;
                    return this;
                }
                return null;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<U_Account, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.Account.Any(where);
            }
        }
    }
}